﻿using System.Threading;
using System.Threading.Tasks;
using System.Net.Http;
using System.Web.Http.Filters;
using System;

namespace Inovout.Web.Http
{
    public class UnhandledExceptionFilter : BaseUnhandledExceptionFilter,IExceptionFilter
    {

        public Task ExecuteExceptionFilterAsync(HttpActionExecutedContext actionExecutedContext, CancellationToken cancellationToken)
        {
            ExceptionContext exceptionContext = actionExecutedContext.Request.GetDependencyScope().GetService(typeof(ExceptionContext)) as ExceptionContext;
            exceptionContext.Exceptions = new Exception[] { actionExecutedContext.Exception };
            base.OnException(exceptionContext);
            return TaskHelper.Completed();
        }


        public bool AllowMultiple
        {
            get { return true; }
        }
    }
}
